var app = require('koa')();
var logger = require('koa-logger');
var serve = require('koa-static');
var router = require('koa-router')();
var path = require('path');
var fs = require('fs');
var xml = require('./tools/parseXml');

app.use(serve(__dirname + '/static'));
app.use(logger());

var routesPath = path.join(__dirname, 'routes');
fs.readdirSync(routesPath).forEach(function(file) {
  if(file[0] === '.') return;
  require(routesPath + '/' + file)(app, router);
});

const options = {
  normalize: true,
  firstCharLowerCase: true,
  explicitArray: false,
  ignoreAttrs: true
}

app.use(xml(options));

app
  .use(router.routes())
  .use(router.allowedMethods());

app.listen(3001);

console.log('http://localhost:3001');
